package mule.presenter;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.stage.Stage;
import mule.model.GameModel;
import mule.view.NewGameOptionView;

/**
 *
 * @author stephen
 */
public final class NewGameOptionPresenter implements Presenter 
{
    private final GameModel model;
    private final NewGameOptionView view;
    private final Stage stage;

    public NewGameOptionPresenter( Stage stage )
    {
        this.stage = stage;
        this.model = GameModel.getInstance();
        this.view = new NewGameOptionView();
    }

    @Override
    public void present() {
        stage.setScene( view.getScreen() );
        addListeners();
        stage.show();
    }

    @Override
    public void addListeners() {
        view.addContinueListener( new EventHandler<ActionEvent>() 
        {
            @Override
            public void handle( ActionEvent event ) 
            {
                model.setNumPlayers( view.getPlayerCount() );
                model.setDifficulty( view.getGameDifficulty() );
                model.setMapType( view.getMapType() );
                model.initializeMap( view.getMapType() );
                PlayerOptionPresenter playerOptionPresenter = new PlayerOptionPresenter( stage, 1 );
                playerOptionPresenter.present();
            } 
        } );
    }
}
